package com.zy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zy.domain.AcceptTask;
import com.zy.domain.ReleaseTask;
import com.zy.mapper.AcceptTaskMapper;
import com.zy.mapper.ReleaseTaskMapper;
import com.zy.param.AcceptTaskParam;
import com.zy.service.AcceptTaskService;
import com.zy.service.ReleaseTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class AcceptTaskServiceImpl extends ServiceImpl<AcceptTaskMapper,AcceptTask> implements AcceptTaskService {
  @Autowired
  private  AcceptTaskMapper acceptTaskMapper;
  @Autowired
  private ReleaseTaskMapper releaseTaskMapper;
  @Override
  public AcceptTask acceptTask(AcceptTaskParam acceptTaskParam) {
//    //订单名称
//    String name = acceptTaskParam.getName();
//    //发布方id
//    String userId = acceptTaskParam.getUserId();
//    //类型
//    String type = acceptTaskParam.getType();
//    //单价
//    Double money = acceptTaskParam.getMoney();
//    //文字验证
//    String phoneNum = acceptTaskParam.getPhoneNum();
//    //置顶到期时间
//    Date endTime = acceptTaskParam.getEndTime();
//    //备注
//    String remarks = acceptTaskParam.getRemarks();
//    //链接
//    String url = acceptTaskParam.getUrl();
    // 发布方的id
//    String releaseUserId = acceptTaskParam.getReleaseUserId();
    //发布订单的id
    Integer rid = acceptTaskParam.getRid();
    LambdaQueryWrapper<ReleaseTask> eq = new LambdaQueryWrapper<ReleaseTask>().eq(ReleaseTask::getId, rid.toString());
    ReleaseTask releaseTask = releaseTaskMapper.selectOne(eq);

    //接单方的id
    String acceptUserId = acceptTaskParam.getAcceptUserId();
    AcceptTask acceptTask=new AcceptTask();
    acceptTask.setRid(rid);
    acceptTask.setUid(acceptUserId);
    acceptTask.setNum(1);
    acceptTask.setState(1);
    acceptTask.setDetail("");
    acceptTask.setDeleteState("Y");
    acceptTask.setOrderTime(new Date());
    int insert = acceptTaskMapper.insert(acceptTask);
    return insert>0?acceptTask:null;
  }
}
